$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});
function update() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/wx/goodsNine/update",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});
}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	console.log("oldStock: "+oldStock);
	$("#signupForm").validate({
		rules : {
			price : {
				required : true,
				min : 0
			},
			stock : {
				required : true,
				max : oldStock,
				min : 0
			},
			rebateOne : {
				required : true,
				min : 0
			},
			rebateTwo : {
				required : true,
				min : 0
			}
		},
		messages : {
			price : {
				required : icon + "请输入价格",
				min : icon + "最小为0"
			},
			stock : {
				required : icon + "请输入库存",
				max : icon + "库存太大",
				min : icon + "最小为0"
			},
			rebateOne : {
				required : icon + "请输入返利",
				min : icon + "最小为0"
			},
			rebateTwo : {
				required : icon + "请输入返利",
				min : icon + "最小为0"
			}
		}
	})
}

//改变事件
$('.chosen-select').on('change', function() {
	var se = $('.chosen-select option:selected');
	console.log("price: "+se.attr("data-price"));
	console.log("stock: "+se.attr("data-stock"));
	$('#oldPrice').val(se.attr("data-price"));
	$('#oldStock').val(se.attr("data-stock"));
	oldStock = se.attr("data-stock");
	/*var opt = {
		query : {
			type : params.selected,
		}
	}
	$('#exampleTable').bootstrapTable('refresh', opt);*/
});